<template>
	<view class="content" style="padding-top: 104rpx;">
		<view style="width: 100%;position: fixed;top: 0;left: 0;background-color: red;">
			<customNavbar :title="$t('titleBat.finan')" @toTime="toTime" :ids="'1'" @send="getrightclick" />
		</view>
		<view class="depositup">
			<!-- <img src="../../static/img/depositup.png" alt=""> -->
		</view>
		<view class="item">
			<view class="item_name">{{$t('first.title99')}}</view>
			<text :class="showmore ? 'item_text':'item_texts'">{{$t('first.title100')}}</text>
			<img @click="changeshow" :class="showmore ? 'img':'imgs'" src="../../static/img/jiantou.png" alt="" />
		</view>
		<view class="item2">
			<!-- <view class="popShow3" v-if="show3">
				<view class="popShow3_item" @click="show3 = false" v-for="(item,index) in 10">{{index}}</view>
			</view> -->
			<view class="item2_top" @click="show3 = true">
				<view class="item_name">{{$t('first.title101')}}</view>
				<view class="item_right">
					{{code}}

					<img src="../../static/img/xia.png">
				</view>
			</view>
			<view class="item2_info">
				<view>{{$t('first.title102')}}</view>
				<view class="item2_btn" @click="show = true">
					{{days}}{{$t('first.title63')}}
					<img src="../../static/img/xia.png">
				</view>
			</view>
			<view class="item2_info">
				<view>{{$t('first.title103')}}</view>
				<view>{{max_rate}}%</view>
			</view>
			
			<view class="item2_info">
				<view>{{$t('first.title133')}}</view>
				<view>{{(Number(min_num)/Number(price)).toFixed(4)}}-{{(Number(max_num)/Number(price)).toFixed(4)}} {{code}}</view>
			</view>
			<view class="item2_info">
				<view>{{$t('first.title104')}}</view>
				<view>{{min_num}}-{{max_num}}U</view>
			</view>
			<text class="item2_text">
				{{$t('first.title105')}}
			</text>
		</view>
		<view class="txBtn" @click="show2 = true">{{$t('first.title56')}}</view>
		<view class="item2">
			<!-- <view class="popShow3" v-if="show4">
				<view class="popShow3_item" @click="show4 = false" v-for="(item,index) in 10">{{index}}</view>
			</view> -->
			<view class="item2_top" @click="show4 = true">
				<view class="item_name">{{$t('first.title106')}}</view>
				<view class="item_right">
					{{code1}}
					<img src="../../static/img/xia.png">
				</view>
			</view>
			<view class="item2_info">
				<view>{{$t('first.title103')}}</view>
				<view>1%</view>
			</view>
			<view class="item2_info">
				<view>{{$t('first.title104')}}</view>
				<view>10-500000U</view>
			</view>
		</view>
		<view class="txBtn" @click="show5 = true">{{$t('first.title56')}}</view>

		<u-picker :show="show" title="days" cancelText="cancel" @change="changeHandler1" keyName="days" confirmText="OK"
			:columns="columns" @cancel="show = false" @confirm="sureChoose"></u-picker>
		<u-picker :show="show3" keyName="code" @change="changeHandler" cancelText="cancel" confirmText="OK"
			:columns="columns5" @cancel="show3 = false" @confirm="confirm1" :closeOnClickOverlay="true"
			@close="show3 = false"></u-picker>
		<u-picker :show="show4" cancelText="cancel" confirmText="OK" :columns="columns4" @cancel="show4 = false"
			@confirm="confirm2" keyName="currency_name" :closeOnClickOverlay="true" @close="show4 = false"></u-picker>
		<view class="mask" v-if='show2'>
			<view
				style="overflow: hidden;width: 60%;;background-color: #ecf0f5;border-radius: 20rpx;padding:50rpx 100rpx">
				<view class="mask_title">{{$t('first.title98')}}</view>
				<u--input class="uInput" :placeholder="(Number(min_num)/Number(this.price)).toFixed(4) + '-' +(Number(max_num)/Number(this.price)).toFixed(4) +' '+ code"
					border="surround" v-model="nums">
					<template slot="suffix">
						<text style="color: #ffb105;font-weight: 800;" @click="max">Max</text>
					</template>
				</u--input>
				<view class="mask_btn">
					<view @click='show2 = false'>cancel</view>
					<view @click='tjbuy'>OK</view>
				</view>
			</view>
		</view>
		<view class="mask" v-if='show5'>
			<view
				style="overflow: hidden;width: 60%;;background-color: #ecf0f5;border-radius: 20rpx;padding:50rpx 100rpx">
				<view class="mask_title">{{$t('first.title98')}}</view>
				<u--input class="uInput" :placeholder="$t('wallet.Please') +  $t('first.title98')"
					border="surround" v-model="nums_d"></u--input>
				<view class="mask_btn">
					<view @click='show5 = false'>cancel</view>
					<view @click='tjbuy_d'>OK</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import customNavbar from './navigationBar.vue'
	import {
		domain
	} from '../../config/domain.js'
	export default {
		components: {
			customNavbar
		},
		data() {
			return {
				type_id: '',
				type_ids: '',
				nums: '',
				nums_d: '',
				show: false,
				show2: false,
				show3: false,
				show4: false,
				show5: false,
				days: '',
				code: '',
				code1: '',
				min_rate: '',
				max_rate: '',
				min_num: '',
				max_num: '',
				min_rates: '',
				max_rates: '',
				min_nums: '',
				max_nums: '',
				types: [],
				columns: [],
				columns2: [],
				columns4: [],
				columns5: [],
				select: [],
				select1: [],
				isDisable:true,
				p:0,
				price:'',
				showmore:true
			}
		},
		onLoad() {
			this.getlist()
			// this.gettype()
			this.gettypes()
			this.userinfo= uni.getStorageSync('userinfo');
		},
		methods: {
			changeshow(){
				this.showmore = !this.showmore
			},
			max(){
				this.nums = (Number(this.max_num)/Number(this.price)).toFixed(4)
			},
			toTime() {
				uni.navigateTo({
					url: '/pages/index/cross?tab=0'
				})
			},
			getlist(){
				var url = domain + 'api/user/currency?type=1';
				var mytype = 'get';
				var userinfo = uni.getStorageSync('userinfo');
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true
				// });
				uni.request({
					url,
					method: mytype,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						'Lang':uni.getStorageSync('lang'),
						'AUTHORIZATION':userinfo.token,
					},
					success: res => {
						this.columns5.push(res.data.list3)
						this.select = res.data.list3[0]
						this.price = res.data.list3[0].price
						res.data.list1.forEach((v, i) => {
							v.currency_name = v.code + 'D'
							this.columns2.push(v)
						})
						this.columns4.push(this.columns2)
					},
					fail: (err) => {
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
			changeHandler(e) {
			},
			changeHandler1(e) {
			},
			sureChoose(e) {
				this.show = false
				this.min_rate = e.value[0].fee_rate
				this.max_rate = e.value[0].rate
				this.max_num = e.value[0].max_number
				this.min_num = e.value[0].min_number
				this.days = e.value[0].days
				this.type_id = e.value[0].id
				
				// this.p = (Number(min_num)/Number(this.price)).toFixed(4)}}-{{(Number(max_num)/Number(this.price)).toFixed(4)
				// this.code=e.value[0].code
			},
			tjbuy() {
				var that = this;
				if(!this.isDisable){
					return;
				}
				this.isDisable=false
				var url=domain + 'api/new_finance_submit';
				var mytype='post';
				var data={
					type_id: this.type_id,
					number: this.nums,
					code:this.code
				}; 
				uni.request({
					url,
					method: mytype,
					data:data,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						'Lang':uni.getStorageSync('lang'),
						'AUTHORIZATION':this.userinfo.token,
					},
					success: res => {
						that.isDisable=true;
						if(res.data.code > 0){
							this.show2 = false
						}
							uni.showToast({
								icon:'none',
								title:res.data.msg 
								// duration:10000
							});
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
			tjbuy_d() {
				if(!this.isDisable){
					return;
				}
				this.isDisable=false
				
				var url=domain + 'api/new_finance_dandu';
				var mytype='post';
				
				var data={
					currency_id: this.type_ids,
					number: this.nums_d,
					finance_id: 1
				}; 
				uni.request({
					url,
					method: mytype,
					data:data,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						'Lang':uni.getStorageSync('lang'),
						'AUTHORIZATION':this.userinfo.token,
					},
					success: res => {
						this.isDisable=true;
						if(res.data.code > 0){
							this.show5 = false
						}
							uni.showToast({
								icon:'none',
								title:res.data.msg 
								// duration:10000
							});
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
			gettype() {
				var url = domain + 'api/new_finance_list';
				var mytype = 'get';
				var userinfo = uni.getStorageSync('userinfo');
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true
				// });
				uni.request({
					url,
					method: mytype,
					header: {
						'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
						'Lang': uni.getStorageSync('lang'),
						'AUTHORIZATION': userinfo.token,
					},
					success: res => {
						this.columns2.push(res.data.data[0].types.currency)
						this.select = res.data.data[0]
						this.select1 = res.data.data[0]
						this.types = res.data.data[0].types
						this.days = res.data.data[0].types[0].days
						this.code = res.data.data[0].types[0].code
						this.code1 = res.data.data[0].types[0].code1
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
			gettypes() {
				this.$utils.initDataToken({
					url: 'new_finance_list',
					type: 'get'
				}, (res, msg) => {


					// res.data[0].types.forEach((v, i) => {
					// 	v.currency_name = v.currency_name + '_D'
					// 	this.columns2.push(v)

					// })

					this.columns.push(res.data[0].types)
					this.select1 = res.data[0]
					this.types = res.data[0].types
					this.days = res.data[0].types[0].days
					this.code = 'BTC'
					this.code1 = res.data[0].types[0].currency.code + "D"
					this.min_rate = res.data[0].types[0].fee_rate
					this.max_rate = res.data[0].types[0].rate
					this.max_num = res.data[0].types[0].max_number
					this.min_num = res.data[0].types[0].min_number
					this.type_id = res.data[0].types[0].id
					this.min_rates = res.data[0].types[0].fee_rate
					this.max_rates = res.data[0].types[0].rate
					this.max_nums = res.data[0].types[0].max_number
					this.min_nums = res.data[0].types[0].min_number
					this.type_ids = res.data[0].types[0].currency.id
					// this.$utils.showLayer(msg); 

				});
			},
			confirm1(e) {
				this.select = e.value[0];
				this.code = e.value[0].code;
				this.price = e.value[0].price;
				this.nums = '';
				this.show3 = false;
			},
			confirm2(e) {
				this.select1 = e.value[0];
				this.code1 = e.value[0].currency_name
				this.min_rates = e.value[0].fee_rate
				// this.max_rates = e.value[0].rate
				// this.max_nums = e.value[0].max_number
				// this.min_nums = e.value[0].min_number
				this.nums_d = '';
				this.type_ids = e.value[0].id
				this.show4 = false;
			},
			getrightclick: function(res) {
				uni.navigateTo({
					url:'./chainRecords'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #ecf0f5;
	}

	.header {
		width: 100%;
		height: 104rpx;
		position: fixed;
		background-color: #ecf0f5;
		display: flex;
		top: 0;
		left: 0;
		align-items: center;
		justify-content: space-between;
		z-index: 999;
	}

	.header image {
		width: 48rpx;
		height: 48rpx;
	}

	.header .text {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: #222;
	}

	.back {
		margin-left: 20rpx;
	}

	.time {
		margin-right: 30rpx;
	}

	.content {
		width: 100%;
		position: relative;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.txBtn {
		width: 90%;
		height: 96rpx;
		margin: 50rpx auto;
		background: #ffb105;
		border-radius: 50rpx;
		font-size: 36rpx;
		font-weight: 600;
		color: #000;
		text-align: center;
		line-height: 96rpx;
	}

	.depositup {
		width: 600rpx;
		height: 0;
		margin-top: 30px;
	}

	.depositup img {
		width: 100%;
		height: 100%;
	}

	.item {
		width: 95%;
		background-image: url('../../static/img/bg.png');
		background-size: 100% 100%;
		padding: 60rpx;
		box-sizing: border-box;
		margin-top: -50rpx;
		
		.item_text{
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 5;
			-webkit-box-orient: vertical;
			font-size: 25rpx;
			color: #686868;
			line-height: 40rpx;
		}
		.item_texts{
			display: -webkit-box;
			font-size: 25rpx;
			line-height: 40rpx !important;
			color: #686868;
		}
		
		.img{
			display: block;
			width: 20px;
			height: 20px;
			margin: 0 auto;
			margin-top: 10px;
			cursor: pointer;
		}
		.imgs{
			display: block;
			width: 20px;
			height: 20px;
			margin: 0 auto;
			margin-top: 10px;
			cursor: pointer;
			transform: rotate(180deg);
		}
	}

	.item2 {
		margin-top: 80rpx;
		width: 95%;
		background: #fff;
		box-shadow: 0 20rpx 37rpx 0 rgba(48, 50, 72, .12);
		border-radius: 50rpx;
		padding: 50rpx;
		box-sizing: border-box;
		// position: relative;
	}


	.popShow3 {
		position: absolute;
		right: -20rpx;
		top: 100rpx;
		width: 200rpx;
		z-index: 10;
		background-color: #fff;
		box-shadow: 0 50rpx 32rpx rgba(50, 50, 51, 0.3)
	}

	.popShow3_item {
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-bottom: 1rpx solid #f9f9fa;
	}

	.item2_top {
		display: flex;
		align-items: center;
		justify-content: space-between
	}

	.item_name {
		font-size: 48rpx;
		font-weight: 600;
		color: #202020;
		margin-bottom: 20rpx;
	}

	.item_right {
		margin-bottom: 20rpx;
		color: #ffb105
	}


	.item_right img {
		width: 20rpx;
		height: 20rpx;
		margin-left: 10rpx
	}

	.item_text,.item2_text {
		font-size: 25rpx;
		color: #686868;
	}

	.item2_info {
		margin: 30rpx 0;
		display: flex;
		justify-content: space-between;
		font-size: 28rpx
	}

	.item2_btn {
		width: 150rpx;
		height: 50rpx;
		border: 5rpx solid #dfdfdf;
		display: flex;
		align-items: center;
		justify-content: center;
	}


	.item2_btn img {
		width: 20rpx;
		height: 20rpx;
		margin-left: 10rpx
	}

	.item2_info view:nth-child(1) {
		color: #999
	}

	.item2_info view:nth-child(2) {
		font-weight: 700;
		color: #222
	}

	// .item2_text {
	// 	font-size: 31rpx;
	// 	font-weight: 600;
	// 	color: #999
	// }

	.mask {
		width: 100%;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.5);
		position: fixed;
		top: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		.mask_title {
			width: 100%;
			text-align: center;
			margin-bottom: 40rpx;
		}

		.mask_btn {
			width: 100%;
			margin-top: 30rpx;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			view {
				flex: 1;
				height: 90rpx;
				text-align: center;
				line-height: 90rpx;
				margin: 0 10rpx;
				border-radius: 20rpx;
			}

			view:nth-child(1) {
				background-color: #fff;
				color: #7c7c7c;
			}

			view:nth-child(2) {
				background-color: #222222;
				color: #fff;
			}
		}
	}
</style>